package com.shanghaionstar.nav;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.UiSettings;
import com.amap.api.maps2d.model.Marker;
import com.onstar.cn.common.exception.OnStarException;
import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.common.util.DeviceUtil;
import com.onstar.cn.common.util.PreferencesUtls;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.annotation.OnClick;
import com.onstar.cn.framework.mvp.base.core.AppScheduler;
import com.onstar.cn.framework.mvp.base.core.BaseFragment;
import com.onstar.cn.framework.utils.RxBus;
import com.onstar.cn.mag.enumtype.RemoteCommandsType;
import com.onstar.cn.map.OMapView;
import com.onstar.cn.map.common.LocationType;
import com.onstar.cn.map.common.PoiItemInfo;
import com.onstar.cn.map.listener.OMapClickListener;
import com.onstar.cn.rxconstants.RxConstants;
import com.onstar.cn.weight.CustomImageView;
import com.shanghaionstar.R;
import com.shanghaionstar.activity.VehicleLoadingActivity;
import com.shanghaionstar.discover.geofence.GeofenceHomeActivity;
import com.shanghaionstar.enumtype.FunctionNameFindId;
import com.shanghaionstar.iview.ILoginAndOutListener;
import com.shanghaionstar.iview.ILoginListener;
import com.shanghaionstar.nav.iview.INavMapView;
import com.shanghaionstar.nav.model.LocateStatus;
import com.shanghaionstar.nav.presenter.NavMapPresenter;
import com.shanghaionstar.nav.service.AbstractMapActivity;
import com.shanghaionstar.nav.share.SharePoiDialog;
import com.shanghaionstar.pin.IPinCallBack;
import com.shanghaionstar.pin.model.PinModel;
import com.shanghaionstar.report.bean.ReportReqParam;
import com.shanghaionstar.utils.AlertDialogUtil;
import com.shanghaionstar.utils.ApplicationUtil;
import com.shanghaionstar.utils.BusinessUtil;
import com.shanghaionstar.utils.FinalConfigParams;
import com.shanghaionstar.utils.FinalConstants;
import com.shanghaionstar.utils.JoinMeConstants;
import com.shanghaionstar.utils.LoadCityList;
import com.shanghaionstar.utils.LoginUtil;
import com.shanghaionstar.utils.MapHandler;
import com.shanghaionstar.utils.NavHolder;

import rx.Subscription;
import rx.functions.Action1;
import rx.functions.Func1;

/**
 * Created by 6335yz on 2016/7/7.
 * 我的位置界面
 */
public class NavMapFragment extends BaseFragment implements INavMapView, IPinCallBack, ILoginListener, ILoginAndOutListener {

    @FindViewById
    private OMapView mapview;
    private AMap aMap;
    @FindViewById(R.id.map_bottomview)
    private LinearLayout map_bottomview;
    private FragmentManager fragmentManager;
    @FindViewById
    private View nav_geofence;

    private NavMapPresenter navMapPresenter;

    private MapHandler mapHandler;
    private AbstractMapActivity mapActivity;

    private String myLocationSnippet;
    private String myLocationtitle;
    @FindViewById(R.id.text_mylocation)
    private TextView text_mylocation;//我的位置
    @FindViewById(R.id.mylocation_info)
    private TextView mylocation_info;//位置信息
    //地图上显示的poi点的poiItemInfo
//    private PoiItemInfo mapPoi_PoiItemInfo;
    //音控导航
    @FindViewById(R.id.btn_send_tbt_view)
    private RelativeLayout btn_send_tbt_view;
    @FindViewById(background = R.drawable.nav_map_tbt_icon)
    private ImageButton btn_send_tbt;
    //车载导航
    @FindViewById(R.id.btn_send_odd_view)
    private RelativeLayout btn_send_odd_view;
    @FindViewById(background = R.drawable.nav_map_odd_icon)
    private ImageButton btn_send_odd;
    private UiSettings mUiSettings;
    @FindViewById
    private CustomImageView nav_clean_map_button, nav_poi_traffic_button;

    @FindViewById
    private View nav_clean_map_view;
    @FindViewById
    private RadioGroup btn_view;
    @FindViewById
    private View view1;
    @FindViewById
    private View navbar_head_view, frame_back;
    @FindViewById
    private RadioButton btn_rim_dealer;
    @FindViewById
    private View nav_my_location_button;

    private LoginUtil mLoginUtil;

    @Override
    public int getLayoutId() {
        return R.layout.nav_map;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mapActivity = (AbstractMapActivity) activity;
        fragmentManager = mapActivity.getSupportFragmentManager();
    }

    /**
     * 初始化弹出框view
     */
    public void initMarkView() {
        //设置bottom view底部选项的点击事件
        setRadioBtnClick();
        mapActivity.setOnMapClickListener(new OMapClickListener() {
            private LocationType locationTypes;
            private Marker markers;
            private PoiItemInfo choosePoi = null;

            @Override
            public void onMarkerClick(LocationType locationType, Marker marker) {
                locationTypes = locationType;
                markers = marker;
                if (locationType == LocationType.MYSELF) {
                    myLocationSnippet = marker.getSnippet();
                    myLocationtitle = marker.getTitle();
                    choosePoi = mapActivity.getNavDataHolder().getMyPoi();
                }
                //用户选择的poi点
                else if (locationType == LocationType.POI) {
//                    BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.ClickPOIfrommap.getStringValue());
                    myLocationSnippet = marker.getSnippet();
                    myLocationtitle = marker.getTitle();
                    choosePoi = mapActivity.getNavDataHolder().getSearchPoi();
                }
                //车辆位置poi点
                else if (locationType == LocationType.VEHICLE) {
                    myLocationSnippet = marker.getSnippet();
                    myLocationtitle = marker.getTitle();
                    choosePoi = mapActivity.getNavDataHolder().getVehiclePoi();
                } else {
                    choosePoi = mapActivity.getNavDataHolder().getMyPoi();
                }
                if (choosePoi != null) {
                    mapActivity.getNavDataHolder().setCurrentMapPoi(choosePoi);
                    showBottomView(choosePoi, true);
                }
            }

            /**
             * 当地图上的bottom view显示时，点击marker之外的区域隐藏bottom view
             */
            @Override
            public void onHideInfoWindow() {
//                if (choosePoi != null) {
                showBottomView(choosePoi, false);
//                }
            }
        });
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (isFirstLoad()) {
            mapview.onCreate(savedInstanceState);
            aMap = mapview.getMap();
            mapHandler = new MapHandler(mapActivity, mapview.getMap());
            mapActivity.initMapHandler(mapHandler);
            mapHandler.initMapView(15);
            navMapPresenter = new NavMapPresenter(mapActivity.getScheduler(), mapActivity, mapHandler);
            navMapPresenter.setView(this);
            navMapPresenter.initOddBtn();
            initMapSetting();
            pinCallBack();
            initMarkView();
            initInputCommand();
            mLoginUtil = new LoginUtil();
            mLoginUtil.loginAndOutShowView(baseActivity, this);
            navMapPresenter.requestMyLocate();
        }
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    public void setRadioBtnClick() {
        btn_view.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.btn_rim_search://周边检索
                        BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Map_SearchSurrounding.getStringValue());
                        mapActivity.addFragment(fragmentManager, NavSearchMoreFragment.newInstance(getResources().getString(R.string.nav_around_search)), true);
                        mapActivity.showFragment(fragmentManager, NavSearchMoreFragment.class, NavMapFragment.class);
                        group.clearCheck();
                        break;
                    case R.id.btn_rim_dealer://周边经销商
                        BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Map_dealerNearby.getStringValue());
//                        BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.POIviewDealerSearch.getStringValue());
                        mapActivity.addFragment(
                                fragmentManager,
                                NavAroundDealerFragment.newInstance(
                                        mapHandler.getMapPoi_PoiItemInfo(),
                                        getArguments() != null ? getArguments().getString(FinalConstants.FROM_PAGE) : null),
                                true);
                        mapActivity.showFragment(fragmentManager, NavAroundDealerFragment.class, NavMapFragment.class);
                        group.clearCheck();
                        break;
                    case R.id.btn_share_location://分享位置
                        BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Map_SharePosition.getStringValue());
//                        BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.POIviewShareLocation.getStringValue());
                        showShareDialog(mapHandler.getMapPoi_PoiItemInfo());
                        group.clearCheck();
                        break;
                    case R.id.btn_path_planing://规划路线
                        BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Map_RoutePlan.getStringValue());
//                        BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.POIviewrouteplanning.getStringValue());
                        PoiItemInfo currentMapPoi = mapActivity.getNavDataHolder().getCurrentMapPoi();
                        if (!CommonUtil.isNull(currentMapPoi)) {
//                            BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.SetAsStartPointButton.getStringValue());
                            if (DeviceUtil.getLanguage().equalsIgnoreCase("en")) {
                                LoadCityList loadCityList = new LoadCityList(mapActivity);
                                currentMapPoi.setCityName(loadCityList.findByZhCity(currentMapPoi.getCityName()));
                            }
                            mapActivity.addFragment(fragmentManager, NavRoutePlanFragment.newInstance(currentMapPoi), true);
                            mapActivity.showFragment(fragmentManager, NavRoutePlanFragment.class, NavMapFragment.class);
                        }
                        group.clearCheck();
                        break;
                }
            }
        });
    }

    /*********************
     * 我是微信分享分割线
     ***********************/
    SharePoiDialog sharePoiDialog;

    private void showShareDialog(PoiItemInfo shareItemInfo) {
        if (sharePoiDialog == null)
            sharePoiDialog = new SharePoiDialog(getContext(), R.style.ShareDialog, shareItemInfo);
        sharePoiDialog.show();
    }
    /*********************我是微信分享分割线***********************/


    /**
     * @param
     * @return void
     * @Title: initMapSetting
     * @Description: 初始化地图的设置信息
     */
    public void initMapSetting() {
        mUiSettings = aMap.getUiSettings();
        //隐藏地图自带的缩放控件
        mUiSettings.setZoomControlsEnabled(true);
        //设置可通过手势缩放
        mUiSettings.setZoomGesturesEnabled(true);
        //指南针
        mUiSettings.setCompassEnabled(false);

        //隐藏清理按钮
        nav_clean_map_view.setVisibility(View.GONE);
    }

    @OnClick({R.id.nav_geofence, R.id.nav_poi_traffic_button, R.id.btn_send_tbt,
            R.id.btn_send_odd, R.id.nav_vehicle_location_button, R.id.nav_clean_map_button,
            R.id.mylocation_info, R.id.nav_my_location_button, R.id.view1, R.id.navbar_head_view, R.id.frame_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.nav_geofence:
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Map_SecurityZone.getStringValue());
                startActivity(new Intent(getActivity(), GeofenceHomeActivity.class));
                break;
            case R.id.nav_poi_traffic_button://路况
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Map_Traffic.getStringValue());
                PreferencesUtls.getInstance(mapActivity).putBoolean(FinalConfigParams.ISTRAFFIC,!mapHandler.getTraffic());
                mapHandler.setTraffic(!mapHandler.getTraffic());
                log.d("current traffic is --->" + mapHandler.getTraffic());
                nav_poi_traffic_button.setBackgroundResource(mapHandler.getTraffic() ? R.drawable.nav_map_traffic_click : R.drawable.nav_map_traffic);

                mapview.postInvalidate();
                mapview.getMap().postInvalidate();

                break;
            case R.id.navbar_head_view:
                mapActivity.showFragment(fragmentManager, NavMainFragment.class, null);
                break;
            case R.id.frame_back:
                mapActivity.showFragment(fragmentManager, NavMainFragment.class, null);
                break;
            case R.id.view1://位置信息
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Map_POIdetail.getStringValue());
//                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.POIviewdetails.getStringValue());
//                mapActivity.changeFragment(fragmentManager, NavPoiDetailFragment.newInstance(mapHandler.getMapPoi_PoiItemInfo()), NavPoiDetailFragment.class, true);
                PoiItemInfo itemInfo = null;
                if (view1.getTag() != null && view1.getTag() instanceof PoiItemInfo)
                    itemInfo = (PoiItemInfo) view1.getTag();
                if (itemInfo == null){
                    itemInfo = mapHandler.getMapPoi_PoiItemInfo();
                }
                if (itemInfo != null) {
                    mapActivity.addFragment(fragmentManager, NavPoiDetailFragment.newInstance(itemInfo), true);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("poiItemInfo",itemInfo);
                    mapActivity.showFragment(fragmentManager, NavPoiDetailFragment.class, getClass(),bundle);
                }
                break;
            case R.id.btn_send_tbt://音控导航 tbt
                BusinessUtil.sendReportByRequestParams(mapActivity, FunctionNameFindId.SendingTBT.getStringValue(),
                        ReportReqParam.getTBTOddClickParams(FunctionNameFindId.SendingTBT.getStringValue(),
                                mapHandler.getMapPoi_PoiItemInfo() == null ? 0 : mapHandler.getMapPoi_PoiItemInfo().getLatitude(),
                                mapHandler.getMapPoi_PoiItemInfo() == null ? 0 : mapHandler.getMapPoi_PoiItemInfo().getLongitude()));
                Bundle tbt = new Bundle();
                tbt.putInt("id", R.id.btn_send_tbt);
                new LoginUtil().loginAndActionCallBack(mapActivity, RxConstants.ACTION_NAV_FAV, NavMapFragment.this, tbt);
//                navMapPresenter.sendTbtOrOdd(mapHandler.getMapPoi_PoiItemInfo(), RemoteCommandsType.COMMANDS_TBT_ROUTE);
//                PollingResult pollingResult = new PollingResult();
//                RxBus.getDefault().post(RxConstants.ALL_PAGE_ALERT, pollingResult);
                break;
            case R.id.btn_send_odd://车载导航 odd
                BusinessUtil.sendReportByRequestParams(mapActivity, FunctionNameFindId.SendingODD.getStringValue(),
                        ReportReqParam.getTBTOddClickParams(FunctionNameFindId.SendingODD.getStringValue(),
                                mapHandler.getMapPoi_PoiItemInfo() == null ? 0 : mapHandler.getMapPoi_PoiItemInfo().getLatitude(),
                                mapHandler.getMapPoi_PoiItemInfo() == null ? 0 : mapHandler.getMapPoi_PoiItemInfo().getLongitude()));
                Bundle odd = new Bundle();
                odd.putInt("id", R.id.btn_send_odd);
                new LoginUtil().loginAndActionCallBack(mapActivity, RxConstants.ACTION_NAV_FAV, NavMapFragment.this, odd);
//                navMapPresenter.sendTbtOrOdd(mapHandler.getMapPoi_PoiItemInfo(), RemoteCommandsType.odd);
                break;
            case R.id.nav_vehicle_location_button://车辆位置
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Map_Locator.getStringValue());
                Bundle vehicle = new Bundle();
                vehicle.putInt("id", R.id.vehicle_locate);
                new LoginUtil().loginAndActionCallBack(mapActivity, RxConstants.ACTION_NAV_FAV, NavMapFragment.this, vehicle);
//                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.NavigationVehicleLocation.getStringValue());
//                navMapPresenter.showPinOrNot(getFragmentManager());
                break;
            case R.id.nav_clean_map_button://清理导航
//                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.NavigatinoClear.getStringValue());
                if (null != mapHandler) {
                    mapHandler.initVariable();
                    mapHandler.clearLocations();
                    mapHandler.clearLayouts();
                    mapHandler.clearOverlay();
                }
                if (NavHolder.getInstance(mapActivity).getLocateStatus() == LocateStatus.LOCATING) {
                    if(!PreferencesUtls.getInstance(mapActivity).getBoolean(FinalConfigParams.LOG_OUT,false)) {
                        AlertDialogUtil.showAlertDialog(mapActivity, R.string.dialog_warning,
                                R.string.poi_not_my_location_str);
                    }
                }
                nav_clean_map_view.setVisibility(View.GONE);
                showBottomView(null, false);
                break;
            case R.id.nav_my_location_button:
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Map_MyPosition.getStringValue());
                navMapPresenter.requestMyLocate();
                break;
        }
    }

    @Override
    public void setLoading(boolean isLoading) {

    }

    @Override
    public void onResponseError(OnStarException e) {
        AlertDialogUtil.showAlertDialog(baseActivity, getString(R.string.dialog_warning), e.getMessage());
    }

    @Override
    public void onReponseSuccess(Object object) {

    }

    @Override
    public Activity onActivity() {
        return null;
    }


    /**
     * 地图底部pop栏
     */
    @Override
    public void showBottomView(PoiItemInfo poiItemInfo, boolean isShow) {
        if (isShow) {
            if (poiItemInfo == null) return;
            ObjectAnimator animator = ObjectAnimator.ofFloat(map_bottomview, "translationY", map_bottomview.getTranslationY(), 0);
            animator.setDuration(100);
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    map_bottomview.setVisibility(View.VISIBLE);
                }
            });
            animator.start();
            if (!CommonUtil.isNull(poiItemInfo.getAddress())) {
                mylocation_info.setText(poiItemInfo.getAddress());
            } else {
                mylocation_info.setText("");
            }
            if (!CommonUtil.isNull(poiItemInfo.getTitle())) {
                text_mylocation.setText(poiItemInfo.getTitle());
            } else {
                text_mylocation.setText("");
            }
            mapHandler.setMapPoi_PoiItemInfo(poiItemInfo);
            view1.setTag(poiItemInfo);
        } else {
            ObjectAnimator animator = ObjectAnimator.ofFloat(map_bottomview, "translationY", map_bottomview.getTranslationY(), map_bottomview.getHeight());
            animator.setDuration(100);
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    map_bottomview.setVisibility(View.GONE);
                }
            });
            animator.start();
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        /**
         * not hidden ,then will show vehicle location on map
         */
        NavHolder.getInstance(mapActivity).setShowMap(!hidden);
        super.onHiddenChanged(hidden);
    }

    @Override
    public void onDestroyView() {
        NavHolder.getInstance(mapActivity).setShowMap(false);
        super.onDestroyView();
    }

    @Override
    public void showOddBtn(boolean isShow) {
        btn_send_odd_view.setVisibility(isShow ? View.VISIBLE : View.GONE);
    }

    private Subscription subscription;

    @Override
    public void pinCallBack() {
        subscription = RxBus.getDefault().toObserverable(RxConstants.NAV_MAP_PAGE, PinModel.class).filter(new Func1<PinModel, Boolean>() {
            @Override
            public Boolean call(PinModel pinModel) {
                return pinModel.isPinSuccess();
            }
        }).subscribeOn(new AppScheduler().backgroundThread())
                .observeOn(new AppScheduler().mainThread()).subscribe(new Action1<PinModel>() {
                    @Override
                    public void call(PinModel pinModel) {
                        if (pinModel.isPinSuccess()) {
                            navMapPresenter.getVehicleLocation();
                        }
                    }
                });
    }

    @Override
    public void showMapLoading(boolean isShow, String msg) {
//        if (progDialog != null) {
//            if (isShow) {
//                if (!progDialog.isShowing()) {
//                    progDialog.setTitle(getString(R.string.waiting));
//                    progDialog.setMessage(msg);
//                    progDialog.show();
//                }
//            } else {
//                if (progDialog.isShowing()) {
//                    progDialog.dismiss();
//                }
//            }
//        }
    }

    @Override
    public void onResume() {
        super.onStop();
        mapview.onResume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mapview.onDestroy();
        if (subscription != null && !subscription.isUnsubscribed()) {
            subscription.unsubscribe();
        }
        navMapPresenter.finish();
        navMapPresenter = null;
        if(mLoginUtil != null)
            mLoginUtil.clearLoginOrOut();
    }

    @Override
    public void onLogin(Bundle bundle, String resultCode) {
        if (RxConstants.ACTION_SUCCESS.equals(resultCode)) {
            if (bundle != null) {
                int id = bundle.getInt("id");
                switch (id) {
                    case R.id.vehicle_locate:
                        navMapPresenter.findVehicleLocation();
                        break;
                    case R.id.btn_send_tbt:
                        if (mapHandler.getMapPoi_PoiItemInfo() != null) {
                            log.d("poi detail when send tbt in map page " + mapHandler.getMapPoi_PoiItemInfo().getAddress() + "," + mapHandler.getMapPoi_PoiItemInfo().getTitle());
                        }
                        navMapPresenter.sendTbtOrOdd(mapHandler.getMapPoi_PoiItemInfo(), RemoteCommandsType.COMMANDS_TBT_ROUTE);
                        NavHolder.getInstance(mapActivity).setCurrentSendPoi(mapHandler.getMapPoi_PoiItemInfo());
                        break;
                    case R.id.btn_send_odd:
                        if (mapHandler.getMapPoi_PoiItemInfo() != null) {
                            log.d("poi detail when send odd in map page " + mapHandler.getMapPoi_PoiItemInfo().getAddress() + "," + mapHandler.getMapPoi_PoiItemInfo().getTitle());
                        }
                        navMapPresenter.sendTbtOrOdd(mapHandler.getMapPoi_PoiItemInfo(), RemoteCommandsType.COMMANDS_NAV_DESTINATION);
                        NavHolder.getInstance(mapActivity).setCurrentSendPoi(mapHandler.getMapPoi_PoiItemInfo());
                        break;
                }
            }
        }
    }

    @Override
    public void onFragmentBackPress() {
        mapActivity.showFragment(fragmentManager, NavMainFragment.class, null);
    }

    @Override
    public void showCommandLoading(boolean isShow) {
        if (isShow) {
            startActivity(new Intent(mapActivity, VehicleLoadingActivity.class));
        }
    }

    @Override
    public void onLogin() {
        //司机和代理没有电子围栏
        if (ApplicationUtil.getInstance().isGen10() &&
                (!JoinMeConstants.PROXY.equalsIgnoreCase(ApplicationUtil.getInstance().getLoginRole())
                        && !JoinMeConstants.DRIVER.equalsIgnoreCase(ApplicationUtil.getInstance().getLoginRole()))) {
            nav_geofence.setVisibility(View.VISIBLE);
        } else {
            nav_geofence.setVisibility(View.GONE);
        }
    }

    @Override
    public void onLoginOut() {
        nav_geofence.setVisibility(View.GONE);
    }

    public static NavMapFragment newInstance(PoiItemInfo poiItemInfo, String fromPage) {
        NavMapFragment navMapFragment = new NavMapFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("poiItemInfo", poiItemInfo);
        bundle.putString(FinalConstants.FROM_PAGE, fromPage);
        navMapFragment.setArguments(bundle);
        return navMapFragment;
    }

    private void initInputCommand() {
        if (getArguments() != null) {
            PoiItemInfo poiItemInfo = (PoiItemInfo) getArguments().getSerializable("poiItemInfo");
            if (poiItemInfo != null) {
                mapHandler.setMapPoi_PoiItemInfo(poiItemInfo);
                btn_rim_dealer.performClick();
                nav_my_location_button.performClick();
            }
        }
    }
}
